package Utils::Constants;

use strict;
use warnings;

use Exporter qw(import);

# Misc constants
use constant BAIDU_MAP_API_ACCESSKEY => "86888b40d197256c44aae7c900378dee";

use constant NEW_MEMBER_DEFAULT_PASSWORD => "sweethome";

use constant USER_ROLE_MAP => {
    0   =>  'admin',
    1   =>  'user',
};

use constant SESSION_TIMEOUT_VALUE => 18000;

use constant CLOUD_FILE_PATH_ROOT => '/home/justin/Shares/sweet_home_files';

use constant TEMPERATURE_DATA_DUMPFILE => '/tmp/temperature.dat';

use constant TEMPERATURE_STATS_PICTURE => 'temperature_linechart.png';

use constant BLOODSUGAR_STATS_IMAGE => 'bloodsugar_linechart.png';

use constant ALERT_RECORD_TYPE_BRIGHTNESS => '1';

use constant ALERT_RECORD_TYPE_FIRESAFETY => '2';

use constant HOME_STATUS_OK => 0;

use constant HOME_STATUS_BAD => 1;

use constant GET_HOUSEWORK_LIMIT => 20;

use constant GET_BLOODSUGAR_HISTORY_LIMIT => 20;

use constant HOUSEWORK_STATUS_COMPLETED => 1;

use constant HOUSEWORK_STATUS_DOING => 0;

use constant FILE_TYPE_DIRECTORY => 0;

use constant FILE_TYPE_COMMON => 1;

use constant RESULT_CODE_NAME => 'resultCode';

use constant RESULT_CODE_PARAM_TYPE_ERROR => "999";

use constant RESULT_CODE_AUTHENTICATION_FAILURE => "998";

use constant RESULT_CODE_FILE_TOO_LARGE_ERROR => "997";

use constant RESULT_CODE_INVALID_FILE => "996";

use constant RESULT_CODE_FOLDER_CREATION_ERROR => "995";

use constant RESULT_CODE_INSUFFICIENT_PRIVILEGE_ERROR => "994";

use constant REG_TEST_NUMBER => qr/\d+/;

use constant REG_TEST_FULLDATETIME => qr/^\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2}$/;

use constant REG_TEST_GEOLOCATION => qr/^\d+(\.\d+)?\,\d+(\.\d+)?$/;

use constant REG_TEST_DATE => qr/^\d{4}-\d{2}-\d{2}$/;

use constant REG_TEST_TIME_WITH_SECOND => qr/^\d{2}\:\d{2}\:\d{2}$/;

use constant REG_TEST_TIME_NO_SECOND => qr/^\d{2}\:\d{2}$/;

use constant REG_TEST_REAL_NUMBER => qr/^\d+(\.\d+)?$/;

# Home Environment Dao SQL
use constant GET_TODAY_HOME_TEMPERATURE_SQL => 'select id,time,value from t_temperature where date(\'now\')=strftime(\'%Y-%m-%d\',time)';

use constant GET_BRIGHTNESS_SQL => 'select * from t_alert_record where type = '.ALERT_RECORD_TYPE_BRIGHTNESS.' order by datetime(time) DESC';

use constant GET_FIRESAFETY_SQL => 'select * from t_alert_record where type = '.ALERT_RECORD_TYPE_FIRESAFETY.' order by datetime(time) DESC';

# Life Assistant Dao SQL
use constant GET_HOUSEWORK_SQL => 'select t_housework.id,t_housework.time,t_housework.task,t_housework.reward,t_user.id as user_id,t_user.name as user_name,t_user.avatar as avatar,t_housework.status from t_housework,t_user where t_user.id=t_housework.user_id and user_id=? order by datetime(time) DESC limit '.GET_HOUSEWORK_LIMIT;

use constant GET_ALL_HOUSEWORK_SQL => 'select t_housework.id,t_housework.time,t_housework.task,t_housework.reward,t_user.id as user_id,t_user.name as user_name,t_housework.status,t_user.avatar as avatar from t_housework,t_user where t_user.id=t_housework.user_id order by datetime(time) DESC limit '.GET_HOUSEWORK_LIMIT;

use constant GET_SPECIFIED_HOUSEWORK_SQL => 'select t_housework.id,t_housework.time,t_housework.task,t_housework.reward,t_user.id as user_id,t_user.name as user_name,t_housework.status,t_user.avatar as avatar from t_housework,t_user where t_user.id=t_housework.user_id and t_housework.id=?';

use constant UPDATE_HOUSEWORK_STATUS_SQL => 'update t_housework set status = '.HOUSEWORK_STATUS_COMPLETED.' where id = ?';

use constant INSERT_NEW_HOUSEWORK_SQL => 'insert into t_housework(time,task,reward,user_id,status) values(datetime(\'now\',\'localtime\'),?,?,?,?)';

use constant GET_BLOODSUGAR_HISTORY_LIST_SQL => 'select * from t_bloodsugar where user_id = ? order by date(date) DESC,time(time) DESC limit '.GET_BLOODSUGAR_HISTORY_LIMIT;

use constant INSERT_NEW_BLOODSUGAR_SQL => 'insert into t_bloodsugar(date,time,tag,value,user_id) values(?,?,?,?,?)';

use constant INSERT_NEW_LOCATION_SQL => 'insert into t_location_track(location_desc,time,user_id) values(?,datetime(\'now\',\'localtime\'),?)';

use constant GET_LOCATION_TRACK_FOR_USER_SQL => 'select * from t_location_track where user_id = ? and date(\'now\')=strftime(\'%Y-%m-%d\',time) order by datetime(time) DESC';

use constant GET_ALL_USERS_LOCATION_TODAY_SQL => 'select t_location_track.id,t_location_track.location_desc,max(t_location_track.time) as time,t_location_track.user_id,t_user.name as user_name,t_user.avatar as user_avatar from t_location_track,t_user where t_user.id=t_location_track.user_id and date(\'now\')=strftime(\'%Y-%m-%d\',time) group by user_id';

use constant INSERT_OR_UPDATE_CONTACTS_BY_USER_ID_SQL => 'replace into t_contacts(user_id, contacts) values(?,?)';

use constant GET_CONTACTS_BY_USER_ID_SQL => 'select contacts from t_contacts where user_id=?';

# System Center Dao SQL
use constant USER_TABLE_NAME => 't_user';

use constant GET_ALL_USERS_SQL => 'select id,name,sex,birth,avatar,email,role from t_user';

use constant GET_USER_BY_ID_SQL => 'select id,name,sex,birth,avatar,email,role from t_user where id = ?';

use constant CHECK_USER_EXISTANCE_SQL => 'select count(*) from t_user where name = ? and password = ?';

use constant GET_USER_BY_NAME_AND_PASSWORD => 'select * from t_user where name = ? and password = ?';

use constant ADD_NEW_USER_SQL => 'insert into t_user(name,role,password) values(?,?,?)';

use constant UPDATE_USER_PASSWORD_SQL => 'update t_user set password = ? where id = ? and password = ?';

use constant RESET_USER_PASSWORD_TO_DEFAULT_SQL => 'update t_user set password = ? where id = ?';

use constant DELETE_USER_SQL => 'delete from t_user where id = ?';

use constant INSERT_OR_UPDATE_BY_USERID_AND_KEY => 'replace into t_option(key, value, user_id) values(?,?,?)';

use constant GET_ALL_OPTIONS_BY_USERID => 'select * from t_option where user_id = ?';

use constant GET_ALL_PRIVILEGES => 'select * from t_privilege';

1;
